import http from "../utils/request"
import {PageRequestType, ResponseType, PageResponseType} from "../types/Response";
import {AxiosResponse} from "axios";

const apiPrefix:string = "/language";

export interface LanguageType {
    // 语言ID
    id?:string|null|undefined
    // 语言名
    language?:string|null|undefined
    // 语言描述
    description?:string|null|undefined
    // 创建时间
    create_at?:any|null|undefined
    // 修改时间
    update_at?:any|null|undefined
}

export interface LanguagePageSearchType extends PageRequestType, LanguageType {

}


export async function addLanguage(data: LanguageType): Promise<AxiosResponse<ResponseType<null>>> {
    return await http.request({
        data: data,
        url: apiPrefix,
        method: 'post'
    })
}

export async function deleteLanguageById(id: string): Promise<AxiosResponse<ResponseType<null>>> {
    return await http.request({
        params: {
            id
        },
        url: apiPrefix+'/id',
        method: 'delete'
    })
}

export async function deleteLanguageByIds(ids: string[]): Promise<AxiosResponse<ResponseType<null>>> {
    return await http.request({
        params: {
            ids
        },
        url: apiPrefix+'/batch',
        method: 'delete'
    })
}


export async function searchLanguageById(id: string): Promise<AxiosResponse<ResponseType<LanguageType>>> {
    return await http.request({
        params: {
            id
        },
        url: apiPrefix+'/id',
        method: 'get'
    })
}

export async function searchLanguage(params?: LanguageType): Promise<AxiosResponse<ResponseType<LanguageType[]>>> {
    return await http.request({
        params: params,
        url: apiPrefix,
        method: 'get'
    })
}

export async function searchLanguageByPage(params: LanguagePageSearchType): Promise<AxiosResponse<ResponseType<PageResponseType<LanguageType>>>> {
    return await http.request({
        params: params,
        url: apiPrefix+'/page',
        method: 'get'
    })
}


export async function updateLanguageById(data: LanguageType): Promise<AxiosResponse<ResponseType<null>>> {
    return await http.request({
        data: data,
        url: apiPrefix,
        method: 'put'
    })
}
